#include "head.h"

TopWidget::TopWidget()
{
//    setStyleSheet("QLabel {background-color: white;}");//设置样式
//        setAutoFillBackground(true);//执行填充
    setAttribute(Qt::WA_TranslucentBackground, true);
}


void TopWidget::setText(const QString &textUp,const QString &textLower)
{
    _textUp = textUp;
    _textLower = textLower;
    repaint();
}

void TopWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event)
    QPainter paintor(this);
    paintor.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform, true);
    paintor.save();
    paintor.setPen(QColor(Qt::white));
    paintor.setFont(QFont("Arial", 15, 50));
    auto original = rect();
    auto upRect = QRect(original.x(), original.y(), original.width(), original.height() - 16);
    paintor.drawText(upRect, Qt::AlignCenter, _textUp);

    paintor.restore();

    paintor.save();
    auto LowerRect = QRect(original.x(), original.y() + upRect.height(), original.width(), 16);
    paintor.setPen(QColor(Qt::white));
    paintor.setFont(QFont("Arial",10,50));
    paintor.drawText(LowerRect, Qt::AlignCenter, _textLower);
    paintor.restore();

}


TopWidget::~TopWidget()
{

}
